import { to } from "await-to-js";
import { signup } from "../db/user";

export default defineEventHandler(async event => {
    const { name, password } = await readBody(event);

    const [error] = await to(signup(name, password));

    if (error) return { msg: error.message, code: 1, data: null };
    else return { msg: 'Sign up successfully!', code: 0, data: null };
});